//
//  SWTabBarController.m
//  新浪微博 OC版
//
//  Created by wszyxc on 16/7/18.
//  Copyright © 2016年 wszyxc. All rights reserved.
//

#import "SWTabBarController.h"

#import "SWHomeController.h"
#import "SWMessageController.h"
#import "SWDiscoverController.h"
#import "SWProfileController.h"

#import "SWTabBar.h"


@interface SWTabBarController ()

@end

@implementation SWTabBarController

- (void)viewDidLoad {
    [super viewDidLoad];


    [self addAllChildVC];
    
    [self setupTabBar];
}


- (void)setupTabBar{
    
    //设置使用自定义的tabbar,由于tabbar是只读的,所以需要使用KVC
    
    SWTabBar *tabBar = [[SWTabBar alloc]init];
    
    //KVC赋值
    [self setValue:tabBar forKey:@"tabBar"];
  
    
}



- (void)addAllChildVC{
    
    //添加首页
    
    SWHomeController *homeVC = [[SWHomeController alloc]init];
    
    [self addOneChildViewController:homeVC WithImage:@"tabbar_home" selectImage:@"tabbar_home_selected" title:@"首页"];
    
    //添加消息
    
    SWMessageController *messageVC = [[SWMessageController alloc]init];
    
    [self addOneChildViewController:messageVC WithImage:@"tabbar_message_center" selectImage:@"tabbar_message_center_selected" title:@"消息"];
    
    //添加发现
    
    SWDiscoverController *discoverVC = [[SWDiscoverController alloc]init];
    
    [self addOneChildViewController:discoverVC WithImage:@"tabbar_discover" selectImage:@"tabbar_discover_selected" title:@"发现"];
    
    //添加我
    
    SWProfileController *profileVC = [[SWProfileController alloc]init];
    
    [self addOneChildViewController:profileVC WithImage:@"tabbar_profile" selectImage:@"tabbar_profile_selected" title:@"我"];
    
}



- (void)addOneChildViewController:(UIViewController *)childVC WithImage:(NSString *)imageName selectImage:(NSString *)selectImageName title:(NSString *)title{
    
    //设置普通状态图片
    childVC.tabBarItem.image = [[UIImage imageNamed:imageName] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
    //设置选中状态图片
    childVC.tabBarItem.selectedImage = [[UIImage imageNamed:selectImageName] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
    //设置标题
    childVC.title = title;
    
    //设置tabBarItem字体
    NSMutableDictionary *mdict = [NSMutableDictionary dictionary];
    
    mdict[NSForegroundColorAttributeName] = [UIColor orangeColor];
    
    [childVC.tabBarItem setTitleTextAttributes:mdict forState:UIControlStateSelected];
    
    UINavigationController *nav = [[UINavigationController alloc]initWithRootViewController:childVC];
    //添加childVC
    [self addChildViewController:nav];
    
    
}



@end
